package com.dhgate.spu.analysis.stat;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

public class B1 {
	public static void main(String[] args) {
//			Long itemcode = 1L;
//			ProdService prodService = ServiceProxyFactory.getServiceProxy(ProdService.class,"2.0.5");
//			System.out.println(prodService);
//			MapProductDTO mapProductDTO = prodService.getMapProductDTO(itemcode);
//			String str = ","+"aaa"+","+"111"+","+"Y";
			
			
//			
//			str += ","+"aaa"+","+"111"+","+"Y";
//			str += ","+"aaa"+","+"111"+","+"Y";
//			int time = getCharTime(str, "Y");
//			
//			String[] nodes = str.split(",");
//			for(int i = 0;i < nodes.length;i++){
//				System.out.println("nodes["+i+"]="+nodes[i]);
//			}
//			
//			for(int i = 1;i < nodes.length;i=i+3){
//				String sTemp = ","+nodes[i]+","+nodes[i+1]+","+nodes[i+2];
//				System.out.println(sTemp);
//			}
		
		String sCurrentLine = "AY,bcdryY";
//		System.out.println(str.substring(str.length()-1).indexOf("Y")!=-1);
//			
//		String s2 = getString(str);
//		System.out.println(str+" "+s2);
//		System.out.println(str.replaceAll("ry", "zz"));
//		
//		
//		String dir = System.getProperty("user.dir");
//		String sep = File.separator;
//		String path = dir+sep+"conf"+sep+"synonyms.txt";
//		System.out.println(path);
		
		int index = sCurrentLine.indexOf(",");
		sCurrentLine = sCurrentLine.substring(index+1);
		System.out.println(sCurrentLine);
		
		Map<String, String> map = new HashMap<String, String>();
		map.put("11111", "a ");
		map.put("22222", "a b c");
		map.put("33333", "a b ");
		
		List<Entry<String, String>> sortList = sortMap(map);
		
		for(Entry<String, String> E:sortList){
			System.out.println(E.getKey()+" "+E.getValue());
		}
		
	}
	public static int getCharTime(String source,String s){
		if(source.indexOf(s) == -1){
			return 0;
		}
		int count = 0;
		for(int i = 0;i < source.length();i++){
			if(s.equals(String.valueOf(source.charAt(i)))){
				count ++;
			}
		}
		return count;
	}
	
	public static String getString(String str){
		return str.replace('Y', 'y');
	}
	
	public static  List<Map.Entry<String,String>> sortMap(Map<String, String> map){
		  List<Map.Entry<String,String>> mappingList = null; 
	  
		  //通过ArrayList构造函数把map.entrySet()转换成list 
		  mappingList = new ArrayList<Map.Entry<String,String>>(map.entrySet()); 
		  //通过比较器实现比较排序 
		  Collections.sort(mappingList, new Comparator<Map.Entry<String,String>>(){ 
		   public int compare(Map.Entry<String,String> mapping2,Map.Entry<String,String> mapping1){ 
		    return mapping1.getValue().length()-(mapping2.getValue().length()); 
		   } 
		  }); 		  			
		  
		return mappingList;
	}
	
}
